package restaurant;

import java.util.ArrayList;
import java.util.Date;

/**
 * The SystemInterface serves as a intermediary between the invoker and the user
 * interfaces.
 * 
 * @author Odessa
 */

public class SystemInterface
{

	/** The invoker. */
	private Invoker invoke;



	/**
	 * Instantiates the system interface.
	 */
	public SystemInterface() {
		invoke = new Invoker();
	}



	/**
	 * Acknowledges a service request.
	 * 
	 * @param waitID the waitperson who acknowledges the request.
	 * @param tableNo the table whose request is being acknowledged.
	 */
	public void acknowledgeRequest(int waitID, int tableNo)
	{
		invoke.acknowledgeRequest(waitID, tableNo);
	}



	/**
	 * Activates a table.
	 * 
	 * @param tableNo the table to activate.
	 * @param pin the pin to activate the table.
	 * @return {@code true} if the table was successfully activated.
	 */
	public String activateTable(int tableNo, int pin)
	{
		boolean activate = invoke.activateTable(tableNo, pin);

		if (activate)
			return "Table Activated.";
		else
			return "Incorrect Pin. Try Again.";
	}



	/**
	 * Adds a new comment.
	 * 
	 * @param comment the comment to add.
	 * @return the newly created comment.
	 */
	public String addComment(String comment)
	{
		Comment c = invoke.createComment(comment);
		return c.toString();
	}



	/**
	 * Adds a new menu item.
	 * 
	 * @param name the name of the item.
	 * @param description the description of the item.
	 * @param price the price of the item.
	 * @param prepTime the time to prepare the item.
	 * @param course the item's course.
	 * @param vegetarian whether or not this item is vegetarian.
	 * @return the newly created menu item.
	 */
	public String addMenuItem(String name, String description, double price,
			int prepTime, String course, boolean vegetarian)
	{
		MenuItem m = invoke.createMenuItem(name, description, price, prepTime,
				course, vegetarian);

		return m.toString();
	}



	/**
	 * Adds a new offer.
	 * 
	 * @param startDate the start date of the offer.
	 * @param endDate the end date of the offer.
	 * @param description the description of the offer.
	 * @param discount the discount of the offer.
	 * @return the newly created offer.
	 */
	public String addOffer(Date startDate, Date endDate, String description,
			double discount)
	{
		Offer o = invoke.createOffer(startDate, endDate, description, discount);
		return o.toString();
	}



	/**
	 * Deletes an offer.
	 * 
	 * @param offer the offer being deleted.
	 */
	public void deleteOffer(int offer)
	{
		invoke.deleteOffer(offer);
	}



	/**
	 * Gets the entire menu.
	 * 
	 * @return the entire menu.
	 */
	public String getMenu()
	{
		Menu menu = invoke.getMenu();
		return menu.toString();
	}



	/**
	 * Gets the menu by course.
	 * 
	 * @param course the course by which to view the menu.
	 * @return the menu based on the {@code course} entered.
	 */
	public String getMenuByCourse(String course)
	{
		Menu menu = invoke.getMenuByCourse(course);
		return menu.toString();
	}



	/**
	 * Gets the menu by preparation time.
	 * 
	 * @param prepTime the preparation time by which to view the menu.
	 * @return the menu based on the {@code prepTime} entered.
	 */
	public String getMenuByPrepTime(int prepTime)
	{
		Menu menu = invoke.getMenuByPrepTime(prepTime);
		return menu.toString();
	}



	/**
	 * Gets the menu by price.
	 * 
	 * @param price the price by which to view the menu.
	 * @return the menu by price based on the {@code price} entered.
	 */
	public String getMenuByPrice(int price)
	{
		Menu menu = invoke.getMenuByPrice(price);
		return menu.toString();
	}



	/**
	 * Gets the menu by rating.
	 * 
	 * @param rating the rating by which to view the menu.
	 * @return the menu based on the {@code rating} entered.
	 */
	public String getMenuByRating(int rating)
	{
		Menu menu = invoke.getMenuByRating(rating);
		return menu.toString();
	}



	/**
	 * Gets the vegetarian menu.
	 * 
	 * @return the menu containing only vegetarian items.
	 */
	public String getMenuByVegetarian()
	{
		Menu menu = invoke.getMenuByVegetarian();
		return menu.toString();
	}



	/**
	 * Indicates an item as being ready for pick up.
	 * 
	 * @param orderNo the order that is ready for pick up.
	 */
	public void itemUp(int orderNo)
	{
		invoke.itemUp(orderNo);
	}



	/**
	 * Places an order for an item.
	 * 
	 * @param tableNo the table placing the order.
	 * @param itemNo the item being ordered.
	 * @param price the price of the item being ordered.
	 */
	public void orderItem(int tableNo, int itemNo, double price)
	{
		invoke.orderItem(tableNo, itemNo, price);
	}



	/**
	 * Indicates an item as being picked up by the waitperson.
	 * 
	 * @param tableNo the table whose order is picked up.
	 */
	public void orderPickup(int tableNo)
	{
		invoke.orderPickup(tableNo);
	}



	/**
	 * Pays an opened tab.
	 * 
	 * @param tableNo the table paying the tab.
	 * @param cardNumber the credit card used to pay the tab.
	 * @param expiration the expiration date of the credit card.
	 * @return {@true} if the payment was successful.
	 */
	public String payTab(int tableNo, String cardNumber, Date expiration)
	{
		boolean pay = invoke.payTab(tableNo, cardNumber, expiration);

		if (pay)
			return "Payment Successful.";
		else
			return "Payment Unsuccessful. Try Agian.";

	}



	/**
	 * Rates a menu item.
	 * 
	 * @param itemNo the menu item being rated.
	 * @param rating the rating for the item.
	 * @param comment the comment for the item.
	 */
	public void rateItem(int itemNo, int rating, String comment)
	{
		invoke.rateItem(itemNo, rating, comment);
	}



	/**
	 * Places a request for service.
	 * 
	 * @param tableNo the table requesting service.
	 */
	public void requestService(int tableNo)
	{
		invoke.requestService(tableNo);
	}



	/**
	 * Allows customer to request a table by providing the number of people in
	 * their party.
	 * 
	 * @param name the name of the customer.
	 * @param numberInParty the number of people in the party.
	 * @return the pin associated with the table.
	 */
	public String requestTable(String name, int numberInParty)
	{
		return invoke.requestTable(name, numberInParty);
	}



	/**
	 * Resets a table.
	 * 
	 * @param tableNo the table number of the table to reset.
	 */
	public void reset(int tableNo)
	{
		invoke.resetTable(tableNo);
	}



	/**
	 * Sets an item's availability.
	 * 
	 * @param item the item number of the item.
	 * @param numAvailable the number of the item available.
	 */
	public void setAvailability(int item, int numAvailable)
	{
		invoke.itemAvailability(item, numAvailable);
	}



	/**
	 * Updates a special offer.
	 * 
	 * @param offer the offer being updated.
	 * @param newStart the new start date of the offer.
	 * @param newEnd the new end date of the offer.
	 * @param newDesc the new description of the offer.
	 * @param newDiscount the new discount provided by the offer.
	 * @return the updated offer.
	 */
	public String updateOffer(int offer, Date newStart, Date newEnd,
			String newDesc, double newDiscount)
	{
		Offer o = invoke.updateOffer(offer, newStart, newEnd, newDesc,
				newDiscount);
		return o.toString();
	}



	/**
	 * Updates a menu item.
	 * 
	 * @param item the item
	 * @param newName the new name of the item.
	 * @param newDesc the new description of the item.
	 * @param newPrice the new price of the item.
	 * @param newTime the new preparation time of the item.
	 * @param newCourse the new course of the item.
	 * @param newVeg whether or not this item is vegetarian.
	 * @return the updated menu item.
	 */
	public String updateMenuItem(int item, String newName, String newDesc,
			double newPrice, int newTime, String newCourse, boolean newVeg)
	{
		MenuItem m = invoke.updateMenuItem(item, newName, newDesc, newPrice,
				newTime, newCourse, newVeg);
		return m.toString();
	}



	/**
	 * View the available tables.
	 * 
	 * @return the available tables.
	 */
	public String viewAvailableTables()
	{
		ArrayList<Table> avail = invoke.getAvailableTables();
		return avail.toString();
	}



	/**
	 * View the average pick up time.
	 * 
	 * @param waitperson the waitperson
	 * @return the average pick up time.
	 */
	public String viewAvgPickUpTime(int waitperson)
	{
		float result = invoke.getAvgPickUpTime(waitperson);
		return "" + result;
	}



	/**
	 * View the comments.
	 * 
	 * @return the comments.
	 */
	public String viewComments()
	{
		ArrayList<Comment> result = invoke.getComments();

		return result.toString();
	}



	/**
	 * View the customer wait queue.
	 * 
	 * @return the customer wait queue.
	 */
	public String viewCustomerWaitQueue()
	{
		ArrayList<Customer> waiting = invoke.getCustomerWaitQueue();
		return waiting.toString();
	}



	/**
	 * View the gross sales for a day.
	 * 
	 * @param day the day to view the sales for.
	 * @return the gross sales for this day.
	 */
	public String viewGrossSales(Date day)
	{
		return invoke.getGrossSales(day);
	}



	/**
	 * View the gross sales for a period.
	 * 
	 * @param start the start date of the period.
	 * @param end the end date of the period.
	 * @return the gross sales for this period.
	 */
	public String viewGrossSales(Date start, Date end)
	{
		return invoke.getGrossSales(start, end);
	}



	/**
	 * View the items sold for a day.
	 * 
	 * @param day the day to view the items sold for.
	 * @return the items sold for this day.
	 */
	public String viewItemsSold(Date day)
	{
		return invoke.getItemsSold(day);
	}



	/**
	 * View the items sold for a period.
	 * 
	 * @param start the start date of the period.
	 * @param end the end date of the period.
	 * @return the items sold for this period
	 */
	public String viewItemsSold(Date start, Date end)
	{
		return invoke.getItemsSold(start, end);
	}



	/**
	 * View the kitchen queue.
	 * 
	 * @return the kitchen queue.
	 */
	public String viewKitchenQueue()
	{
		ArrayList<Order> kitchen = invoke.getKitchenQueue();
		return kitchen.toString();
	}



	/**
	 * View the offers.
	 * 
	 * @return the offers.
	 */
	public String viewOffers()
	{
		return invoke.getOffers().toString();

	}



	/**
	 * View the orders.
	 * 
	 * @return the orders.
	 */
	public String viewOrders()
	{
		ArrayList<Order> orders = invoke.getOrders();
		return orders.toString();
	}



	/**
	 * View the ratings for a menu item.
	 * 
	 * @param item the item to view the ratings for.
	 * @return the ratings of this item.
	 */
	public String viewRatings(int item)
	{
		ArrayList<Comment> ratings = invoke.getRatings(item);
		return ratings.toString();
	}



	/**
	 * View the tab for a table.
	 * 
	 * @param tableNo the table to view the tab for.
	 * @return the tab for this table.
	 */
	public String viewTab(int tableNo)
	{
		Tab tab = invoke.getTab(tableNo);
		return tab.toString();
	}



	/**
	 * View occupied tables.
	 * 
	 * @return the occupied tables.
	 */
	public String viewAssignedTables()
	{
		ArrayList<Table> used = invoke.getAssignedTables();
		return used.toString();
	}



	/**
	 * View tables waiting on their order to be delivered.
	 * 
	 * @return the tables waiting on their order to be delivered.
	 */
	public String viewWaitingTables()
	{
		ArrayList<Table> waiting = invoke.getWaitingTables();
		return waiting.toString();
	}
}
